/**
4 * index页面的业务js
 */
// 全局变量
var bck01;// 当前页面选中的部门ID
var isChoseWait = false;// 候诊病人
var isOwnchose = false;// 我的病人和本科病人
var pageSize = 50;//医嘱列表单页显示数量
var curr = 1;
var cbm01;
var valueArr = {};// 参数
var ruyuanbingrenVaoList;
var zhenduanyijuHtml;//诊断依据
var zhenduanyieguoHtml;//诊断结果
var zhenduanindex=1;//诊断内容ID递增序数
var shouyeActiveId;
var timeId;//记录单击事件延迟时间
var bce03;
var houzhenTbleList;
var houzhenTbleList_houtai;//后台查询的
var myJieZhenTbleList;
var benkeZhenTbleList;
var wanZhenTbleList;
var bck01s="";
var isShuaka = false;
var pinquiry = false;
//新开页面打印的内容
var jibingList=[];//自费疾病列表
var yibaoJibingList=[];//医保疾病列表
var dataObjT = {};
var hccode;//医院编码
var vac01_;
var zhenjinVajList=[];
var beginTime;
var endTime;
var zhenjinList=[];//接诊时诊金列表
var fenzhen=1;
var isonlyJieZhen = false; //只接诊不呼叫
// 界面初始化完成后加载的脚本
$(document).ready(function() {
	yiyuanId =$("#hospital").val();
	initSelectChekbox();//页面初始化select \checkbox
	isShowClinics();
	$.ajax({url:rootUrl+"/clidoctor/getBce03",type:"get",dataType:"json",data:{"bce01":bce01},success:function(data){bce03 = data.map.bce03}});
	$.ajax({url:rootUrl+"/clidoctor/getHccode",type:"get",dataType:"json",data:{"yiyuanId":yiyuanId},success:function(data){hccode = data.map.hccode}});
	departmentList();
	handleAdmission();
	newOrder();
	addJyFenzuguize();// 检验报告分组规则添加
	addJianchaFenzu();//检查报告分组规则添加
	showJiuzhenfanwei();//接诊范围参数控制
	loadSelectAllList();//加载诊断信息下拉列表数据
	autoExpand();
	//搜索按钮注册事件
	searchHouzhenren();
	clickBtnsousuo();
	deptCloseEvent();
});
//页面中根据参数设置的功能
function setPageByParams(){
	configCurrentDate(); //设置病人列表开始时间
	controlCheckItem(); //检查详情是否显示
	//初始化solr索引库
	if (valueArr.p_100_105002_407=='1')
	{
		initSolrIndex();
	}
	//医嘱附加信息的默认展开或者隐藏
	var temp = valueArr["p_100_105002_394"];
	if(temp == "1"){
		$(".patient_operation").removeClass("expand");
	}else if(temp == "2"){
		$(".patient_operation").addClass("expand");
	}
	yizhuOtherInfo(); //医嘱附件信息展开还是收缩
	
	var jiezhenfw = valueArr.p_100_105002_100;
	if(jiezhenfw=="05" || jiezhenfw=="05")
	{
		$("#varjiezhen_fanwei").html("全院病人");
	}
	if(valueArr.p_9999_9999_102==1 || valueArr.p_9999_9999_102=="1")
	{
		fenzhen=0;
	}
	else
	{
		fenzhen=1;
	}
	timingReflushPatientWait();//启动定时刷新候诊列表的任务
}
//加载疾病列表
function loadJibingList(){
	//加载新开页面的自费疾病树形结构数据
	$.ajax({url:rootUrl+"/treatment/jibingList",data:{params:JSON.stringify({yiyuanId:yiyuanId})},dataType:'json',type:'get', success:function(data){if(data)
	{
		jibingList = data.list;
	}}});
	//加载新开页面的医保疾病列表
	$.ajax({url:rootUrl+"/treatment/yibaoJibingList",data:{params:JSON.stringify({corporationid:yiyuanId})},dataType:'json',type:'get', success:function(data){if(data)
	{
		yibaoJibingList = data.list;
	}}});
}
//页面初始化select \checkbox
function initSelectChekbox(){
	/*页面上select2 控件初始化,改为一个一个初始化，医嘱类型初始化*/
	$("#bdaSearch").select2({language: "zh-CN"});
	$('#departmentList').select2({
				placeholder : '请选择科室',
				allowClear : true,
	});
	$('#all_clinics').select2({
		placeholder : '请选择诊室',
		allowClear : true,
	});
	$("#advice_disort").select2({language: "zh-CN"})
	$('input').iCheck({
	    checkboxClass: 'icheckbox_square-blue',
	    radioClass: 'iradio_square-blue',
	    increaseArea: '20%' // optional
	});
	var contentMainState = true;
	$("#doc_directionBtn").click(function(){
		if(contentMainState){
			$('#content').animate({'left':0},200);
			$("#doc_directionBtn").animate({'left':0},200);
			contentMainState = false;
		}
		else{
			$('#content').animate({'left':320},200);
			$("#doc_directionBtn").animate({'left':320},200);
			contentMainState = true;
		}
	})
}
//根据参数判断是否显示诊室
function paiban(){
    var prm = {};
    prm.productId = 100;
    prm.programId = 103005;
    prm.paramNo = 51;
    var mode = parseInt(getSystemParam(prm));
    return mode;
}
function isShowClinics(){

	var mode = paiban();
	if(mode  == 1){
		$(".console-items-content .console-right").remove();
		
	}else{
		loadAllClinicsM();
	}
}
function controlCheckItem(){
	if(valueArr['p_100_105002_408'] ==1){
		$("#check_detail_info").removeClass("hidden");
	}
}

/**
 * 初始化solr的索引库
 */
function initSolrIndex()
{
	debugger;
	if(valueArr.p_100_105002_407=='1'){
//		$.get(rootUrl+"/solr/initAdviceIndex",{params:JSON.stringify({"yiyuanId":yiyuanId,"bck01":bck01})},function(){});
//		$.ajax({url:rootUrl+"/solr/initzhenduanIndex",data:{params:JSON.stringify({corporationid:yiyuanId})},dataType:'json',type:'get', success:function(data){}});
//		//加载新开页面的医保疾病列表
//		$.ajax({url:rootUrl+"/solr/inityibaozhenduanIndex",data:{params:JSON.stringify({corporationid:yiyuanId})},dataType:'json',type:'get', success:function(data){}});
	}
}

/**
 * 加载诊断信息下拉数据
 */
function loadSelectAllList()
{
	//诊断依据
	var url2 = rootUrl + "/cliparamter/yijuList";
	var params2 = {};
	$.get(url2, params2, function(data2) {
		
		var list2 = data2.list;
		zhenduanyijuHtml = "<select>";
		zhenduanyijuHtml += "<option value='-1'>-请选择-</option>";
		for (var i = 0; i < list2.length; i++) {
			var option ="<option value="+list2[i]["bgp01"]+">"+list2[i]["bgp02"]+"</option>";
			zhenduanyijuHtml += option;
		}
		zhenduanyijuHtml+="</select>";
		//诊断结果
		var url3 = rootUrl + "/cliparamter/zhenduanjieguoList";
		var params3 = {};
		$.get(url3, params3, function(data3) {
			var list3 = data3.list;
			zhenduanyieguoHtml ="<select>";
			zhenduanyieguoHtml += "<option value='-1'>-请选择-</option>";
			for (var j = 0; j < list3.length; j++) {
				var option ="<option value="+list3[j]["ady01"]+">"+list3[j]["ady02"]+"</option>";
				zhenduanyieguoHtml += option;
			}
			zhenduanyieguoHtml+="</select>";
			shouyeEvent();//首页
		});
	});
}
// 获取界面参数设置
function getAllParams() {
	debugger;
	$.ajax({
		url : rootUrl + "/patientsearch/findSysparams",
		data : {userid:userId,bck01:bck01},
//		async : false,
		success : function(data) {
			var list = data.list;
			for (var i = 0; i < list.length; i++) {
				valueArr[list[i]["para_key"]] = list[i]["value"];
			}
			setPageByParams();
			// 加载完参数，加载候诊和接诊列表
			asyncHouzhenTable();
			asyncMyPatientTable();
			loadJibingList();
		}
	});
}

//接诊范围根据参数设置显示
function showJiuzhenfanwei(){
	var map={
			"01":"本科室病人",
			"02":"本科室病人",
			"03":"本科室病人",
			"04":"本科室病人",
			"05":"全院病人",
			"06":"全院病人"
	}
	$("#jiezhen_fanwei").text(map[valueArr['p_100_105002_100']]);
}

// 医嘱单全选事件
function choseAllEvent() {
	var all = $("#advice_table table thead").find("input[type='checkbox']");
	var sub = $("#advice_table table tbody").find(".innerHead").find("input[type='checkbox']");
	$(all).on('ifChecked', function(event){
		$(sub).iCheck('check');
	});
	$(all).on('ifUnchecked', function(event){
		$(sub).iCheck('uncheck');
	});
}

function configCurrentDate() {
	var dl1 = new Date();
	dl1.setDate(dl1.getDate() - Number(valueArr['p_100_105002_149']));
	$("#dl1").val(dl1.Format("yyyy-MM-dd"));
	$("#dl2").val(new Date().Format("yyyy-MM-dd"));
}
// 门诊医生系统科室列表
function departmentList() {
	$.ajax({
		url : rootUrl + "/patientsearch/finddepartments",
		type : "get",
		dataType : 'json',
		data:{"bce01":bce01,"bck01":yiyuanId},
		success : function(data) {
			departmentList = data.list;
			var html = "";
			for (var i = 0; i < departmentList.length; i++) {
				bck01s += ","+departmentList[i]["bck01"];
				html = html + "<option id=\"" + departmentList[i]["bck01"]+"\" value=\"" + departmentList[i]["bck01"]
						+ "\" name=\""+departmentList[i]["bck02"]+"\">" + departmentList[i]["bck03"] + "</option>";
			}
			$("#departmentList").html(html);
			bck01s = bck01s.substring(1,bck01s.length);
			bck01s = "("+bck01s+")";
			var bck01Obj = $("#departmentList");
			bck01 = $(bck01Obj).find("option:selected").attr("id");
			if (typeof (bck01) == "undefined") {
				bck01 = $(bck01Obj).find("option:first").attr("id");
			}
			getAllParams();
//			benkeJiezhenPatientList();
//			loadWabZhenPatient();//完诊病人
		}
	});
}
/**
 * 切换科室的事件处理
 */
//不直接用chang事件，用select2的close事件
function deptCloseEvent(){
	$("#departmentList").on("select2:close", function() {  
		debugger;
		qiehuanBck1();
	}); 
	
}
function qiehuanBck1()
{
	bck01 = $("#departmentList").val();
	var jiezhenfw = valueArr.p_100_105002_100;
	if(jiezhenfw!="05" && jiezhenfw!="06"){
		layer.msg('查询中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'}); 
		bck01 = $("#departmentList").find("option:selected").attr("id");
		asyncHouzhenTable();
		initSolrIndex();
	}else{
		refreshListJiezhen();
	}
}
// 根据科室刷新候诊\就诊列表
function refreshListHouzhen() {
	layer.msg('查询中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'}); 
	bck01 = $("#departmentList").find("option:selected").attr("id");
	asyncHouzhenTable();
	refreshListJiezhen();
}
// 根据科室刷新候诊\就诊列表
function refreshListJiezhen() {
	$("#search_patinet").attr("disabled",true);
	layer.msg('查询中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*100}); 
	asyncMyPatientTable();
	$("#all_patient").find(".active").trigger("click");
//	benkeJiezhenPatientList();
//	loadWabZhenPatient();
}
// 根据科室刷新候诊\就诊列表--接诊专用
function refreshListJiezhen_jiezhen() {
	$("#search_patinet").attr("disabled",true);
	layer.msg('查询中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*100}); 
	TasyncMyPatientTable();
//	benkeJiezhenPatientList();
//	loadWabZhenPatient();
	if (valueArr.p_100_105002_107=="1")
	{
		$("#newpage").trigger('click');
	}
}
/**
 * 控制button的状态
 */
function changeButtonState()
{
	$("#newpage").removeAttr("disabled");
	$("#bj").removeAttr("disabled");
	$("#sc").removeAttr("disabled");
	$("#zf").removeAttr("disabled");
	$("#fasong").removeAttr("disabled");
	$("#down_more").removeAttr("disabled");
	$("#hujiao").removeAttr("disabled");
	$("#patientInfo1").removeAttr("disabled");
	$("#shouye_btn_down").removeAttr("disabled");
	 if($.inArray("allowfbr",authorityArr)==-1)
	{
		if (wanzhenType)
		{
			$("#newpage").removeAttr("disabled");
			$("#bj").removeAttr("disabled");
			$("#sc").removeAttr("disabled");
			$("#zf").removeAttr("disabled");
			$("#fasong").removeAttr("disabled");
			$("#down_more").removeAttr("disabled");
			$("#hujiao").removeAttr("disabled");
			$("#patientInfo1").removeAttr("disabled");
			$("#shouye_btn_down").removeAttr("disabled");
			$(".wanzhen_li").siblings().show();
		}
		else
		{
			$("#newpage").attr("disabled", true);
			$("#bj").attr("disabled", true);
			$("#sc").attr("disabled", true);
			$("#zf").attr("disabled", true);
			$("#fasong").attr("disabled", true);
			$(".wanzhen_li").siblings().hide();
			//		$("#down_more").attr("disabled",true);
			$("#hujiao").attr("disabled", true);
			$("#patientInfo1").attr("disabled", true);
			//		$("#shouye_btn_down").attr("disabled",true);
		}
	}
	 else
	 {
		 wanzhenType = true;
	 }
}
/*候诊病人刷新*/
function reflushPatientWait(days){
	$("#reflush_patient_wait").attr("disabled",true);
	layer.msg('刷新中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*200}); 
	asyncHouzhenTable(days);
}

/**
 * 定时刷新候诊病人列表
 */
function timingReflushPatientWait()
{
	if (valueArr["p_100_105002_103"]=="1")
	{
		setInterval("houzhenPatientList()", parseInt(valueArr["p_100_105002_104"]) * 1000);
	}
}
/*
 * 根据人名过滤候诊病人为选中状态(两种方式：1点击查询按钮，2回车键查询)
 */
// 点击查询按钮
function clickBtnsousuo() {
	$("#sousuoHouzhenBtn").on("click", function() {
		layer.msg('查询中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*100}); 
		sousuoHouzhen();
	})
}
// 查询事件
function sousuoHouzhen() {
	var str = $("#houzheSearchStr").val().toUpperCase();
	var menzhenStr = $("#houzheSearchStr").val();
	reloadTable(str, houzhenTbleList, "patient_wait");
	//接诊列表从后台查询
	refreshListJiezhen();
//	reloadTable(str, myJieZhenTbleList, "myjiezhenTableList");
//	reloadTable(str, benkeZhenTbleList, "jiezhenBenkeTable");
//	reloadTable(str, wanZhenTbleList, "wanzhenBenkeTable");
	
	//查询到候诊病人自动新开
	if(valueArr['p_100_105002_106']=="1" && str!="")
	{
		$("#patient_wait").setSelection(1);
		$("#"+1,'#patient_wait').trigger("dblclick");
	}
}
function reloadTable(str, list, tableId)
{
	debugger;
	if(str)
	{
		str = str.toUpperCase();
	}
	if(list == undefined){
		list = [];
	}
	var resultList = [];
	for(var i =0;i<list.length;i++)
	{
		if((list[i].vaa02 && (list[i].vaa02.indexOf(str)&&list[i].vaa02.indexOf(str)>=0)) || (list[i].vaa03.indexOf(str)&&list[i].vaa03.indexOf(str))>=0 
				|| (list[i].vaa05.indexOf(str)&&list[i].vaa05.indexOf(str))>=0 || (list[i].name&&list[i].name.indexOf(str)>=0))
		{
			resultList.push(list[i]);
		}
	}
	$('#'+tableId).clearGridData().setGridParam({data:resultList,rowNum: resultList.length}).trigger("reloadGrid");
}
// 回车键查询
function searchHouzhenren() {
	$("#houzheSearchStr").keydown(function(e) {
		if (e.which === 13) {
			sousuoHouzhen();
		}
	});
}
function addCellAttr1(rowId, val, rawObject, cm, rdata) {
    if (rawObject.vac43 == 2) {
        return "style='background-color:#7CCD7C'";
    }else if(rawObject.vac43 == 3){
    	return "style='background-color:#FE9700'";
    }
}
function reloadPatientInfo(lvac01)
{
	isChoseWait = true;
	$("#vac01").val(lvac01);
	$("#bck01").val(bck01);
	$.ajax({
		url : rootUrl + "/patientsearch/getpatientinfo",
		data : {
			"productid" : 100,
			"programid" :103010,
			"paramno" : 29,
			"lVAC01" : lvac01
		},
		type : 'post',
		dataType : 'json',
		async:false,
		success : function(data) {
			if(data){
				var list = $.extend(data.list[0],{status:0})
				$("#vaa01").val(data.list[0]['vaa01']); //重要
//				bck01 = data.list[0]['bck01a'];
				//初始化solr索引库
				if (data.list[0] && data.list[0]['bck01a'] != $("#departmentList").find("option:selected").attr("id") && valueArr.p_100_105002_407=='1')
				{
					//$.get(rootUrl+"/solr/initAdviceIndex",{params:JSON.stringify({"yiyuanId":yiyuanId,"bck01":data.list[0]['bck01a']})},function(){});
				}
				if(list.vcj20){
					var p_v = list.vcj20.split(":")[0];
					var s_v = list.vcj20.split(":")[1];
					list.vcj20 = p_v
					var danwei;
					switch (s_v)
					{
						case "1" :
							danwei = "空腹";
							break;
						case "2" :
							danwei = "餐后";
							break;
						case "3" :
							danwei = "随机";
							break;
					}
					list.vcj20_d = danwei;
				}
				//根据儿童参数判断显示详细年龄
			 	var prm = {};
		        prm.productId = 1;
		        prm.programId = 117001;
		        prm.paramNo = 2;
				var mode = parseInt(getSystemParam(prm));
				if(parseInt(list.vaa10)<= parseInt(mode)){
					 var detail_age = (list.vac68).replace("Y","岁").replace("M","月");
					 list.vaa10 = detail_age;
				}
				$(".three-column").data(list);
			    laytplUrl(myurl + "/module/patient_more_info.html",list, function(data, html) {
			    	 $(".header-content-left").empty().append(html);
				});
				var info = $.extend(list,{lvac01:lvac01})
				loadActiveTabInfo(info);
			}
		}
	});
}
//选择病人后，根据显示的页签加载该页签的列表
function loadActiveTabInfo(info){
	//医嘱记录
	patientDoctorAdvice(info.lvac01, 1);
	var activeTab = $("#patient_info").find(".active").trigger("click");
}
function seeMoreInfoEvent(){
	if(isOwnchose||isChoseWait){
		var flag = $(".three-column").find(".main-header").hasClass('br_expanded');
		if(flag){
			$(".three-column").find(".main-header").removeClass('br_expanded');
			$(".three-column").find(".main-header").css('height','35px');
			$(".three-column").find('.more-info-text').text('更多');
			$(".three-column").find(".btn-transparent").find('.caret').removeClass('caret-top');
			$('.main-content').css('top','35px');
			
		}else{
			$(".three-column").find(".main-header").addClass('br_expanded');
			$(".three-column").find(".main-header").css('height','110px');
			$(".three-column").find('.more-info-text').text('收起');
			$(".three-column").find(".btn-transparent").find('.caret').addClass('caret-top');
			$('.main-content').css('top','115px');
		}
	}
}
function yizhuOtherInfo(that){
	var flag = $("#patient_operation").hasClass("expand");
	if(flag){
		$('.yizhu_content_table').animate({'height':"92%"},"fast");
		$(".patient_operation").removeClass("expand");
		$(".patient_operation").find('.more-info-text').text('展开');
		$(".yizhujilu_content").hide();
		$(".patient_operation").find('.caret').addClass('caret-top');
		
	}else{
		$('.yizhu_content_table').animate({'height':"55%"},"fast");
		$(".patient_operation").find('.more-info-text').text('收缩');
		$(".patient_operation").addClass("expand");
		$(".yizhujilu_content").show();
		$(".patient_operation").find('.caret').removeClass('caret-top');
	}
}

function autoExpand(){
	$(".patient_operation li").on("click",function(){
	if(!$(this).hasClass("moreCont")){
		var tab = $(this).parents(".tab-pane");
		if(($(this).parents(".patient_operation ").find(".yizhujilu_content").is(":hidden"))){
			tab.find('.yizhu_content_table').animate({'height':"55%"},"fast");
			tab.find(".patient_operation").find('.more-info-text').text('收缩');
			tab.find(".patient_operation").addClass("expand");
			tab.find(".yizhujilu_content").show();
			tab.find(".patient_operation").find('.caret').removeClass('caret-top');
		}
	}
	})
}
// table折叠
function zhedie() {
	$(".innerHead").find("button").on("click",function() {
				var e=arguments.callee.caller.arguments[0]||event; 
				if (e && e.stopPropagation) { 
					// this code is for Mozilla and Opera
					e.stopPropagation(); 
				} else if (window.event) { 
					// this code is for IE 
					window.event.cancelBubble = true; 
				} 
				if ($(this).parents("tr").siblings().css("display") == "none") {
					$(this).parents("tr").find("lable").removeClass(
							"glyphicon glyphicon-chevron-up")
					$(this).parents("tr").find("lable").addClass(
							"glyphicon glyphicon-chevron-down");
					$(this).parents("tr").siblings().removeClass("hidden");
				} else {
					$(this).parents("tr").find("lable").removeClass(
							"glyphicon glyphicon-chevron-down");
					$(this).parents("tr").find("lable").addClass(
							"glyphicon glyphicon-chevron-up");
					$(this).parents("tr").siblings().addClass("hidden");
				}
				$(this).parents("tr").find("input[type='checkbox']").iCheck('uncheck');
			})
}

function sendJiezhen(row)
{
	debugger;
	$.ajax({
		url: mqUrl+'/Mq/MQ/eliminateTopic' ,
		type:"GET",
		async: false,
		data: {
			topicName : msgName,
			userId : bce01,
			messageType : JSON.stringify({bce01s:"(1,2)",row:row,type:"sendJiezhen"}),
			 jsessionids:jsessionids
		},
		timeout : 1000, //超时
		dataType:"jsonp",
		success:function(json){
		}
	});
}
//完诊
function wanzhen()
{
	var rowid = $("#myjiezhenTableList").jqGrid('getGridParam','selrow');
	var row = $("#myjiezhenTableList").jqGrid("getRowData", rowid);
	
	if (!rowid) 
	{
		layer.msg("请选择要完诊的病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}
	else
	{
		var flag1 =false,flag2=false;
		$.when
		(
				//检查该病人是否有医嘱839
				/*$.post(rootUrl+"/doctoradvice/checkpatientdoctoradvice",{vaa01:$("#vaa01").val(),vaf06:$("#vac01").val()},function(data){
					if(data && data.list && data.list.length>0)
					{
						debugger;
						flag1 = true;
					}
				}),*/
				
				//检查该病人是否有未发送的医嘱838
				$.post(rootUrl+"/doctoradvice/checkPatientDoctorAdviceUnSend",{vaf06:$("#vac01").val()},function(data){
					if(data && data.list && data.list.length<=0)
					{
						debugger;
						flag2 = true;
					}
				})
				
		).done(function(){
					debugger;
					//修改医嘱状态更新完诊时间
					/*if(!flag1)
					{
						layer.msg("该病人没有医嘱，不能完诊！", {
							time : 2000,
							icon : 2,
							skin: 'layui-layer-msg2'
						});
						return;
					}
					else */
					if(!flag2)
					{
						layer.msg("该病人有未发送的医嘱，不能完诊！", {
							time : 2000,
							icon : 2,
							skin: 'layui-layer-msg2'
						});
						return;
					}
					else if (flag2)
					{
						$.post(rootUrl+"/doctoradvice/wanchengjiezhen",{vac01:$("#vac01").val()},function(data){
							if(data && data.result=="Success")
							{
								//刷新接诊病人和完诊病人
								asyncMyPatientTable();
								loadWabZhenPatient();
								layer.msg("完诊成功！", {
									time : 2000,
									icon : 1,
									skin: 'layui-layer-msg1'
								});
							}
							else
							{
								layer.msg("完诊失败！", {
									time : 2000,
									icon : 0,
									skin: 'layui-layer-msg0'
								});
							}
						})
					}
					else
					{
						layer.msg('完诊失败，联系管理员！',{time:3000,icon:2,skin: 'layui-layer-msg2'});
						return;
					}
				}
		);
	}
	
}


// 转诊
function zhuanzhen() {
	var that = this;
	var selId = $("#myjiezhenTableList").jqGrid("getGridParam",'selrow');
	var row = $("#myjiezhenTableList").jqGrid('getRowData',selId);
	if (!selId) {
		layer.msg("请选择要转诊的就诊病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	} else {
		$.ajax({
			url : rootUrl + "/patientsearch/finddepartments2",
			type : "get",
			data:{"bce01":bce01,"bck01":yiyuanId},
			dataType : 'json',
			success : function(data) {
				that.laytplUrl(myurl + "/module/menzhen_zhuanzhen.html",data, function(data, html) {
							var index = layer.open({
								type : 1,
								// scrollbar : false,
								title : "病人院内转诊",
								area : [ "400px", "270px" ],
								shade : 0.1,
								// maxmin : true,
								content : html,
								closeBtn : 1,
								success : function() {
									$("select").select2({
										language: "zh-CN"
									})
									$("#remove_action_zz").on("click",function(){
										layer.close(index);
									})
								loadBce1();
								}
							})
				  });
			 }
		});
	}

}

/**
 * 院内转诊
 */
function clinic_change_bck1() {
	var url = rootUrl + "/clinicalreceptiontransfer/clinicchangebck1";
	var params = {};
	var selId = $("#myjiezhenTableList").jqGrid("getGridParam",'selrow');
	var row = $("#myjiezhenTableList").jqGrid('getRowData',selId);
	params.lVAC01 = $("#vac01").val();
	params.lVAA07 = $("#vac01").val();
	params.lBCK01 = $("#zhuanrukeshi").find("option:selected").val();
	params.lBCE01 = $("#jiezhenyishi").find("option:selected").val();
	params.lBCE03 = $("#jiezhenyishi").find("option:selected").text();
	params.lBCE01A = bce01;
	params.lBCK01A = $("#bck01a").val();
	params.BAS02 = 1;
	debugger;
	$.post(url, params, function(data) {
		if (data.result == "Success") {
			layer.msg("转诊成功！", {
				time : 2000,
				icon : 1,
				skin: 'layui-layer-msg1'
			});
			layer.closeAll();// 关闭弹出层
			refreshListHouzhen();
		} else {
			layer.msg(data.resultMsg, {
				time : 2000,
				icon : 3,
				skin: 'layui-layer-msg3'
			});
		}
	});
}

// 根据bck01加载医师列表
function loadBce1() {
	var bck01 = $("#zhuanrukeshi").find("option:selected").val();
	var url = rootUrl + "/treatment/loadBce1";
	var params = {};
	params.bck01 = bck01;
	$("#jiezhenyishi").empty();
	$.get(url, params, function(data) {
		var list = data.list;
		var option = $("<option>").attr('value', 0).text("请选择");
		$("#jiezhenyishi").append(option);
		for (var i = 0; i < list.length; i++) {
			var option = $("<option>").attr('value', list[i]['bce01']).text(
					list[i]['bce03']);
			$("#jiezhenyishi").append(option);
		}
	});
}
// 医嘱单tr选中事件
function adviceChoseTr() {
	$("#advice_table").find(".yizhu_details").on("click",function() {
				$(this).addClass("choseedTr").siblings().removeClass("choseedTr");
				$(this).parents("tbody").siblings().find("tr").removeClass("choseedTr");
	});
}
// 病人医嘱记录
function patientDoctorAdvice(lvac01, curr) {
	var that = this;
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	var days =  valueArr["p_9999_9999_117"];
	$.ajax({
		url : rootUrl + "/doctoradvice/getpatientsdoctoradvice",
		type : "post",
//		async : false,
		data : {
			"lVAF06" : lvac01,
			"lVAF04" : 1,
			"lBCE01A" : bce01,
			date1:dl1,
			date2:dl2,
			days:days,
//			currPage : curr,
//			pageSize : pageSize,
			VAF74 : "",
			VAF36 : ""
		},
		dataType : 'json',
		success : function(data) {
			that.laytplUrl_T(myurl + "/module/advice_table.html", data,
					function(data, html) {
						$("#advice_table").html(html);
						choseAllEvent();// 全选事件
						otherProperties();
						checkboxEvent1();
						checkboxEvent4();
						checkboxEvent8();
						advicetongzu();// 同组记录
						adviceChoseTr();// 医嘱tr选中事件
						backAdviceStyle();//医嘱作废样式
						zhedie();// table折叠
						//icheck初始化
						$("#advice_table").find('input').iCheck({
						    checkboxClass: 'icheckbox_square-blue',
						    radioClass: 'iradio_square-blue',
						    increaseArea: '20%' // optional
						  });
						//分页暂时不用
						/*var totalPage = 1;
						var pages = parseInt(data.total) % parseInt(pageSize);
						if (pages == 0) {
							totalPage = parseInt(data.total)
									/ parseInt(pageSize);
						} else {
							totalPage = parseInt(data.total - pages)
									/ parseInt(pageSize) + 1
						}
						laypage({
							cont : 'page',
							pages : totalPage,
							skip : true, // 是否开启跳页
//							skin : '#33b818',
							groups : 5, // 连续显示分页数
							curr : curr || 1,
							jump : function(obj, first) {
								if (!first) {
									patientDoctorAdvice(lvac01, obj.curr);
								}
							}
						});*/
					});
			
		}
	});
}
//作废样式
function backAdviceStyle(){
	$(".yizhu_details").each(function(index, ele) {
		var fstatus=JSON.parse($(ele).attr("data-info")).fstatus;
		if(fstatus=="医嘱退费"){
			$(this).addClass("backAdvice");
		}
	})
}
// 医嘱单同组
function advicetongzu() {
	var tzTdindex = [ 3, 6 ];
	$("#advice_table tbody").each(function(index, ele) {
		var vaf59Arr = [];
		var adviceList = $(ele).find(".yizhu_details");
		for (var k = 0; k < adviceList.length; k++) {
			var dataobj = JSON.parse($(adviceList[k]).attr("data-info"));
			if(dataobj.bda01 == 1||dataobj.bda01 == 2){ //西药
				vaf59Arr.push(dataobj.vaf59);
			}
		}
		if(vaf59Arr.length>0){
			vaf59Arr = vaf59Arr.unique2();
			var resultArr = [];
			for (var i = 0; i < vaf59Arr.length; i++) {
				var tongzuEditArr = [];
				for (var j = 0; j < adviceList.length; j++) {
					if (JSON.parse($(adviceList[j]).attr("data-info")).vaf59 == vaf59Arr[i]) {
						tongzuEditArr.push($(adviceList[j]).index());
					}
				}
				if (tongzuEditArr.length > 1) {
					
					for (var m = 0; m < tzTdindex.length; m++) {// 要同组的tr
						// 的下标
						for (var n = 0; n < tongzuEditArr.length; n++) { // 同组的td
							// 的下标[3,6]
							if (n == 0) { // 同组tr为第一行的，只把td的bottom
								// 去掉
								$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").addClass("xiyaoTzCss");
							} else if (n == (tongzuEditArr.length - 1)) {// 如果为最后一行，只把text隐藏
								$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").text("");
							} else {// 如果为中间的tr，则隐藏text,并bottom 去掉
								$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").text("");
								$($(ele).find("tr")[tongzuEditArr[n]]).find("td:eq("+ tzTdindex[m]+ ")").addClass("xiyaoTzCss");
							}
						}
					}
				}
			}
		}
	})
}

// 新开页面：
function newOrder() {
	var that = this;
	$("#newpage").on("click",function() {
		$("#newpage").attr("disabled",true);
		debugger;
		var table_id;
		var cur_tab = $("#all_patient").find(".active a").attr("href");
		if(cur_tab == "#mypatinent1"){
			table_id = "myjiezhenTableList";
			
		}else if(cur_tab == "#benkepatient1"){
			table_id = "jiezhenBenkeTable";
		}
		var selectedId = $("#"+table_id).jqGrid("getGridParam", "selrow")
		var selectRow =$("#"+table_id).jqGrid("getRowData", selectedId);
		var isoperate = isOperateAdvice();
		if(!isoperate){
			layer.msg("该病人已经过了开嘱期限，请重新挂号！",{ time: 3000,icon: 0,skin: 'layui-layer-msg0'});
			return false;
		}
		$("#newpage").attr("disabled",true);
				var vaa01 = $("#vaa01").val();
				var vac01_n = $("#vac01").val();
				if (wanzhenType && selectedId && vac01_n&&selectRow.vac01==vac01_n) {
					var vaa05 = selectRow.vaa05;
					var age = $("#age").text();
					var kaidankeshi = $("#departmentList").find("option:selected").attr("id");
					var indexN = layer.open({
						type : 2,
						title : '新开医嘱--'+vaa05,
						area : [ "95%", "95%" ],
						shade : 0.3,
						maxmin : true,
						id:"neworder_layer",
						content :myurl+"/neworder.jsp?vaa01="+vaa01+"&vac01="+vac01_n+"&bck01="+$("#bck01a").val()+"&vaa05="+vaa05+"&age="+age+"&kaidankeshi="+kaidankeshi,
						cancel: function(indexN){ 
							$(".layui-layer-close").blur();//让关闭按钮失去焦点，避免回车重复触发
							//跨域保存病历
							orderInIndex();
							return false;
							},
						success:function(layero){
//							iframeName = $(layero).find("iframe").attr("name");
							$("#newpage").removeAttr("disabled");
						},		
						min: function (layero) {
			                var times = layero.attr('times');
			                $('#layui-layer-shade' + times).hide();
			            },
			            restore: function (layero) {
			                var times = layero.attr('times');
			                if ($('#layui-layer-shade' + times).css('display') == 'none') {
			                    $('#layui-layer-shade' + times).show();
			                }
			            },

					});
				} else {
					layer.msg("请选择就诊病人", {
						time : 2000,
						icon : 0,
						skin: 'layui-layer-msg0'
					});
				}
				$("#newpage").removeAttr("disabled");
			});
}
// 根据医嘱状态查询医嘱（前端实现）
function checkboxEvent1()
{
	$('#vaf10_1').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").show();
	});
	$('#vaf10_1').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('新开')").parents("tbody").hide();
	});

}
// 发送
function checkboxEvent8()
{
	$('#vaf10_8').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").show();
	});
	$('#vaf10_8').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('已发送')").parents("tbody").hide();
	});
}
function checkboxEvent4()
{
	// 作废
	$('#vaf10_4').on('ifChecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").show();
	});
	$('#vaf10_4').on('ifUnchecked', function(event)
	{
		$("#advice_table tbody tr").find("td:eq(2)").filter(":contains('医嘱退费')").parents("tbody").hide();
	});
}
// 医嘱记录更多操作
function moreOperation() {
	$(".patient_operation .moreCont").on("click", function() {
		if ($(".yizhujilu_content").css("display") == "none") {
			$("#table_list").addClass("hidden");
			$(".yizhujilu_content").removeClass("hidden");
			$(".patient_operation .moreCont").text("折叠");
		} else {
			$("#table_list").removeClass("hidden");
			$(".yizhujilu_content").addClass("hidden");
			$(".patient_operation .moreCont").text("展开");
		}

	})
}
 
function headPrice(cbm01)
{
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	$.post(rootUrl+"/doctoradvice/doctoradvicedetail",{"lCBM01":cbm01,"date1":dl1,"date2":dl2},function(data)
	{
		vbd_jqgrid(data.list);
	});
}


// 医嘱单选定，并查看医嘱信息
function otherProperties()
{
	loadZhenjinEditTable();
	$(".innerHead").on("click",function()
	{
		if($(this).find("input:checked").length>0){
			$(this).find("input[type='checkbox']").iCheck('uncheck');
		}else{
			
			$(this).find("input[type='checkbox']").iCheck('check');
		}
		var cbm01 = $(this).attr("data-cbm01list");
		var data_info = $($(this).parents("tbody").find(".yizhu_details")[0]).attr("data-info");
		var vaf10 = JSON.parse(data_info).vaf10;
		var vaf01 = JSON.parse(data_info).vaf01;
		var dl1 =$("#date1_p").val();
		var dl2 =$("#dl2").val();
		debugger;
		if(vaf10==1)
		{
			//1349
			$.post(rootUrl+"/doctoradvice/doctoradvicepriceinfo",{"lCBM01":cbm01,"ABC02":$("abc02").text(),"date1":dl1,"date2":dl2},function(data)
					{
						$("#vaf1Fasongjilu_table").empty();
						vbd_jqgrid(data.list);
					});
		}
		else if(vaf10==8)
		{
			//1402
			dataObjT={fun:'1',cbm01:cbm01};
			headPrice(cbm01);
			//1405 医嘱单发送记录
			$.post(rootUrl+"/doctoradvice/sendadvicehistory",{"lCBM01":cbm01,"date1":dl1,"date2":dl2},function(data)
					{
				var list = data.list;
				$("#vaf1Fasongjilu_table").empty();
	    		for(var i= 0;i<list.length;i++)
	    		{
	    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
	    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
	    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
	    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
	    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
	    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
	    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
	    			var td9 = $("<td>"+(list[i]["vai04"]?list[i]["vai04"]:'')+"</td>");
	    			var td10 = $("<td>"+(list[i]["vbi21"]?list[i]["vbi21"]:'')+"</td>");
	    			var tr = $("<tr></tr>");
	    			tr.append(td1);
	    			tr.append(td2);
	    			tr.append(td3);
//	    			tr.append(td5);
	    			tr.append(td6);
	    			tr.append(td7);
	    			tr.append(td8);
	    			tr.append(td9);
	    			tr.append(td10);
	    			$("#vaf1Fasongjilu_table").append(tr);
	    		}
					});
		}
		//7501 医嘱单处方属性
		var params = {};
		params.iaa01 = 0;
		params.acf01 = 1;
		
		params.vaf01 = vaf01;
	    	$.post(rootUrl+"/doctoradvice/doctoradviceprescriptionproperty",params,function(data){
	    		var list = data.list;
	    		$("#chufangshuxing_table tbody").empty();
	    		for(var i= 0;i<list.length;i++)
	    		{
	    			var td1 = $("<td>"+(list[i]["cbm07"]?list[i]["cbm07"]:'')+"</td>");
	    			var td2 = $("<td>"+(list[i]["bjw02"]?list[i]["bjw02"]:'')+"</td>");
	    			var td3 = $("<td>"+(list[i]["iai03"]?list[i]["iai03"]:'')+"</td>");
	    			var tr = $("<tr></tr>");
	    			tr.append(td1);
	    			tr.append(td2);
	    			tr.append(td3);
	    			$("#chufangshuxing_table tbody").append(tr);
	    		}
	    	});
		//1176 医嘱单处方诊断//暂时注释掉，新的在zhenduan.js
	    	adviceDiagnose(cbm01,'chufang_zhenduan');
	});
	$(".yizhu_details").on("click", function(e)
	{
		$(this).addClass("choseedTr").parent().siblings().find(".yizhu_details").removeClass("choseedTr");
		
		var dataStr = $(this).attr("data-info");
		var dataObj = JSON.parse(dataStr);
		cbm01 = dataObj.cbm01;
		dataObjT={fun:'2',dataObj:dataObj};
		vbdInfo(dataObj);
		// 处方诊断
		adviceDiagnose(dataObj.cbm01,"chufang_zhenduan");
		// 处方性质
		chufangshuxing(dataObj.vaf01,"chufang_xingzhi");
		// 手术人员安排
		shouShuRenYuanAnpai(dataObj.vaf01);
		//1405 医嘱单发送记录
		sendAdviceHistory(dataObj.vaf01,dataObj.cbm01,"jizhu_fasong");
		// 加载打印医嘱列表
		// printAdvice(bda01);
	})
}
function sendAdviceHistory(vaf01,cbm01,tabid){
	debugger;
	var target = $("#"+tabid).find("tbody");
	var dl1 =$("#date1_p").val();
	var dl2 =$("#dl2").val();
	$.post(rootUrl+"/doctoradvice/sendadvicehistory_vaf",{"vaf01":vaf01,"cbm01":cbm01,"date1":dl1,"date2":dl2},function(data)
			{
		
		var list = data.list;
		target.empty();
		for(var i= 0;i<list.length;i++)
		{
			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
			var td9 = $("<td>"+(list[i]["vai04"]?list[i]["vai04"]:'')+"</td>");
			var td10 = $("<td>"+(list[i]["vbi21"]?list[i]["vbi21"]:'')+"</td>");
			var tr = $("<tr></tr>");
			tr.append(td1);
			tr.append(td2);
			tr.append(td3);
			/*tr.append(td5);*/
			tr.append(td6);
			tr.append(td7);
			tr.append(td8);
			tr.append(td9);
			tr.append(td10);
			target.append(tr);
		}
			});
}
// 打印选中医嘱单，添加打印类型
function printCheckedEvent(){
	$(".dropdown-menu select").select2();
	if ($(".innerHead td input:checked").length <= 0)
	{
		layer.msg("请勾选要打印的医嘱单",
		{
		time : 2000,
		icon : 0,
		skin: 'layui-layer-msg0'
		});
		return;
	}
	else if($(".innerHead td input:checked").length > 1)
	{
		layer.msg("只能勾选一个已发送的医嘱单",
				{
				time : 2000,
				icon : 0,
				skin: 'layui-layer-msg0'
				});
				return;
	}
	else
	{
			var dataStr=$($(".innerHead td input:checked").parents("tbody").find(".yizhu_details")[0]).attr("data-info");
			var dataObj = JSON.parse(dataStr);
			cbm01 = dataObj.cbm01;
			var bda01 = dataObj.bda01;
			var vaf10 = dataObj.vaf10;
			if(vaf10!=8)
			{
				layer.msg("请先发送医嘱单",
						{
						time : 2000,
						icon : 0,
	    				skin: 'layui-layer-msg0'
						});
						return;
			}
			printAdvice(bda01,vaf10,dataObj.cbm07);//vaf10 判断是否是医嘱单状态
		}
}

// 加载打印格式下拉列表
function printAdvice(bda01,vaf10,cbm07) {
	var rid;
	switch (bda01)
	{
		case "1" :
			rid = justXiyaoType(cbm07,rid);
			break;
		case "2" :
			rid = justXiyaoType(cbm07,rid);
			break;
		case "8" :
			rid = 25;
			break;
		case "E" :
			rid = 22;
			break;
		case "L" :
			rid = 23;
			break;
		case "S" :
			rid = 28;
			break;
		case "4" :
			rid = 999;//待定
			break;
		case "M" :
			rid = 999;//待定
			break;
		default ://治疗
			rid = 190;
			break;
	}
	var html ="";
	var myAjax = $.ajax({
		url : printUrl + "/printtemprest/findListByRid/" + rid+"?jsessionids="+$.cookie('jsessionids'),
		type : "get",
		async : true,
		dataType : "json",
		traditional : true,
		success : function(data) {
			var defaultV1;
			for (var i = 0; i < data.length; i++) {
				var obj = {};
				obj.vaf10 = vaf10;
				obj.id = data[i]['id'];
				if (data[i]['xdefault'] == "1") {
					defaultV1 = data[i].id;
					 html += '<option data-info='+JSON.stringify(obj)+' value='+data[i].id+'>'+data[i]['name']+'</option>';
				} else {
					 html += '<option data-info='+JSON.stringify(obj)+' value='+data[i].id+'>'+data[i]['name']+'</option>';
				}
			}
			$("#advice_print").empty().append(html);
			$("#advice_print").select2();
			if(defaultV1){
				
				$("#advice_print").val(defaultV1).trigger("change");
			}
			if (bda01=="1")
			{
				$(".iswest").show();
				var html1 = "";
				//输液卡
				$.ajax(
				{
				url : printUrl + "/printtemprest/findListByRid/" + 101 + "?jsessionids=" + $.cookie('jsessionids'),
				type : "get",
				async : false,
				dataType : "json",
				traditional : true,
				success : function(data)
				{
					var defaultV2;
					for (var i = 0; i < data.length; i++)
					{
						var obj = {};
						obj.vaf10 = vaf10;
						obj.id = data[i]['id'];
						if (data[i]['xdefault'] == "1")
						{
							defaultV2 = data[i].id;
							html1 += '<option data-info=' + JSON.stringify(obj) + ' value='+data[i].id+'>' + data[i]['name'] + '</option>';
						}
						else
						{
							html1 += '<option data-info=' + JSON.stringify(obj) + ' value='+data[i].id+'>' + data[i]['name'] + '</option>';
						}
					}
					$("#advice_print_shuye").empty().append(html1);
					$("#advice_print_shuye").select2();
					if(defaultV2){
						
						$("#advice_print_shuye").val(defaultV2).trigger("change");
					}
				}
				});
				//皮试单
				var html2="";
				$.ajax(
						{
							url : printUrl + "/printtemprest/findListByRid/" + 102 + "?jsessionids=" + $.cookie('jsessionids'),
							type : "get",
							async : false,
							dataType : "json",
							traditional : true,
							success : function(data)
							{
								var defaultV3;
								for (var i = 0; i < data.length; i++)
								{
									var obj = {};
									obj.vaf10 = vaf10;
									obj.id = data[i]['id'];
									if (data[i]['xdefault'] == "1")
									{
										defaultV3 = data[i].id;
										html2 += '<option data-info=' + JSON.stringify(obj) + '  value='+data[i].id+'>' + data[i]['name'] + '</option>';
									}
									else
									{
										html2 += '<option data-info=' + JSON.stringify(obj) + '  value='+data[i].id+'>' + data[i]['name'] + '</option>';
									}
								}
								$("#advice_print_pishi").empty().append(html2);
								$("#advice_print_pishi").select2();
								if(defaultV3){
									
									$("#advice_print_pishi").val(defaultV3).trigger("change");
								}
							}
						});
				
			}
			else
			{
				$("#advice_print_shuye").empty();
				$("#advice_print_pishi").empty();
				$(".iswest").hide();
			}
			
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.msg('打印服务器连接失败！', {
				time : 2000,
				icon : 3,
				skin: 'layui-layer-msg3'
			});
		}
	});

}
//选择打印格式
function chosePrintType(){
	 var e=arguments.callee.caller.arguments[0]||event; 
	 if (e && e.stopPropagation) { 
	  // this code is for Mozilla and Opera
	  e.stopPropagation(); 
	 } else if (window.event) { 
	  // this code is for IE 
	  window.event.cancelBubble = true; 
	 } 
}

// 医嘱打印预览
function print1() {
	debugger;
	var datastr = $("#advice_print option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl + "/printtoolrest/printToPdfView/" + id + "?cbm01="
			+ cbm01+"&jsessionids="+$.cookie('jsessionids');
			window.open(url);
		}else{
			if(vaf10 == '1'){
				layer.alert("请先发送医嘱单！");
			}else if(vaf10 == '4'){
				layer.alert("医嘱已作废，请重开！");
			}
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}
function print11() {
	var datastr = $("#advice_print_shuye option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl + "/printtoolrest/printToPdfView/" + id + "?cbm01="
			+ cbm01+"&jsessionids="+$.cookie('jsessionids');
			window.open(url);
		}else{
			if(vaf10 == '1'){
				layer.alert("请先发送医嘱单！");
			}else if(vaf10 == '4'){
				layer.alert("医嘱已作废，请重开！");
			}
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}
function print111() {
	var datastr = $("#advice_print_pishi option:selected").attr("data-info");
	if(datastr){
		var dataObj = JSON.parse(datastr);
		var id = dataObj.id;
		var vaf10 = dataObj.vaf10;
		if(vaf10 == '8'){
			var url = printUrl + "/printtoolrest/printToPdfView/" + id + "?cbm01="
			+ cbm01+"&jsessionids="+$.cookie('jsessionids');
			window.open(url);
		}else{
			if(vaf10 == '1'){
				layer.alert("请先发送医嘱单！");
			}else if(vaf10 == '4'){
				layer.alert("医嘱已作废，请重开！");
			}
		}
	}else{
		layer.msg("请选择打印的医嘱单！",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}


// 加载病人的处方诊断信息
function chufangzhenduan(vaf01) {
	var url = rootUrl + "/doctoradvice/doctordiagnosis";
	var params = {};
	params.lVAF01 = vaf01;
	params.acf01 = 1;
	$.post(url, params, function(data) {
		var list = data.list;
		$("#chufangzhenduan_table").empty();
		for (var i = 0; i < list.length; i++) {
			var tr = $("<tr></tr>");
			var td2 = $("<td></td>");
			var td22 = $("<td>" + (list[i]["vao15"]?list[i]["vao15"]:'') + "</td>");
			tr.append(td2);
			tr.append(td22);
			$("#chufangzhenduan_table").append(tr);
		}
//		tr.append(td1);
	})
}
    
    
    
    //加载病人处方属性
    function chufangshuxing(vaf01,tabid)
    {
    	var target = $("#"+tabid).find("tbody");
    	var url = rootUrl + "/doctoradvice/doctoradviceprescriptionproperty";;
    	var params= {};
    	params.iaa01 = 0;
    	params.acf01 = 1;
    	params.vaf01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		
    		target.empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["cbm07"]?list[i]["cbm07"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["bjw02"]?list[i]["bjw02"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["iai03"]?list[i]["iai03"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			target.append(tr);
    		}
    	});
    }
    
    //加载手术人员安排
    function shouShuRenYuanAnpai(vaf01)
    {
    	var url = rootUrl + "/doctoradvice/queryoperationscheduled";;
    	var params= {};
    	params.VAF01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#shoushurenyuananpai_table tbody").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+list[i]["ace02"]+"</td>");
    			var td2 = $("<td>"+list[i]["bce02"]+"</td>");
    			var td3 = $("<td>"+list[i]["bce03"]+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			$("#shoushurenyuananpai_table").append(tr);
    		}
    	});
    }
    
    //医嘱发送记录(草药和手术)
    function vaf1Fasongjilu3(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/herbandoperationsendhistory";;
    	var params= {};
    	params.lVAFID = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'未结账')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi05"]?list[i]["vbi05"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    
    //医嘱发送记录(西药)
    function vaf1Fasongjilu1(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/sendpharmacyhistory";;
    	var params= {};
    	params.lVAF01 = vaf01;
    	params.lVAF01A = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi01"]?list[i]["vbi01"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    
    
    //医嘱发送记录(其它)
    function vaf1FasongjiluOther(vaf01)
    {
    	var url = rootUrl + "/sendadvicehistory/otheradvicesendhistory";
    	var params= {};
    	params.VAF01 = vaf01;
    	$.post(url,params,function(data){
    		var list = data.list;
    		$("#vaf1Fasongjilu_table").empty();
    		for(var i= 0;i<list.length;i++)
    		{
    			var td1 = $("<td>"+(list[i]["fvbi15"]?list[i]["fvbi15"]:'')+"</td>");
    			var td2 = $("<td>"+(list[i]["vbi09"]?list[i]["vbi09"]:'')+"</td>");
    			var td3 = $("<td>"+(list[i]["nbby05"]?list[i]["nbby05"]:'')+"</td>");
    			var td5 = $("<td>"+(list[i]["vbi07"]?list[i]["vbi07"]:'')+"</td>");
    			var td6 = $("<td>"+(list[i]["bck03"]?list[i]["bck03"]:'')+"</td>");
    			var td7 = $("<td>"+(list[i]["bce03a"]?list[i]["bce03a"]:'')+"</td>");
    			var td8 = $("<td>"+(list[i]["fvbi13"]?list[i]["fvbi13"]:'')+"</td>");
    			var td9 = $("<td>"+(list[i]["vbi05"]?list[i]["vbi05"]:'')+"</td>");
    			var tr = $("<tr></tr>");
    			tr.append(td1);
    			tr.append(td2);
    			tr.append(td3);
    			tr.append(td5);
    			tr.append(td6);
    			tr.append(td7);
    			tr.append(td8);
    			tr.append(td9);
    			$("#vaf1Fasongjilu_table").append(tr);
    		}
    	});
    }
    //医嘱直接打印
    function print()
    {
    	debugger;
    	$(".iswest").show();
    	$(".print_btn").attr("disabled",true);

    	if ($(".innerHead td input:checked").length <= 0)
    	{
    		layer.msg("请勾选要打印的医嘱单",
    		{
    		time : 2000,
    		icon : 0,
    		skin: 'layui-layer-msg0'
    		});
    		$(".print_btn").removeAttr("disabled");
    		return;
    	}
    	else if($(".innerHead td input:checked").length > 1)
    	{
    		layer.msg("只能勾选一个已发送的医嘱单",
    				{
    				time : 2000,
    				icon : 0,
    				skin: 'layui-layer-msg0'
    				});
    		$(".print_btn").removeAttr("disabled");
    				return;
    	}
    	else
    	{
    			var dataStr=$($(".innerHead td input:checked").parents("tbody").find(".yizhu_details")[0]).attr("data-info");
    			var dataObj = JSON.parse(dataStr);
    			cbm01 = dataObj.cbm01;
    			var bda01 = dataObj.bda01;
    			var vaf10 = dataObj.vaf10;
    			if(vaf10!=8)
    			{
    				layer.msg("请先发送医嘱单",
    						{
    						time : 2000,
    						icon : 0,
    	    				skin: 'layui-layer-msg0'
    						});
    				$(".print_btn").removeAttr("disabled");
    						return;
    			}
//    			var flag = $("#advice_print option:selected").attr("data-info");
//    			if(flag){
//    				print_content();
//    			}else{
    				
    			var rid;
    			switch (bda01)
    			{
    				case "1" :
    					rid = justXiyaoType(dataObj.cbm07,rid);
    					break;
    				case "2" :
    					rid = justXiyaoType(dataObj.cbm07,rid);
    					break;
    				case "8" :
    					rid = 25;
    					break;
    				case "E" :
    					rid = 22;
    					break;
    				case "L" :
    					rid = 23;
    					break;
    				case "S" :
    					rid = 28;
    					break;
    				case "4" :
    					rid = 999;//待定
    					break;
    				case "M" :
    					rid = 999;//待定
    					break;
    				default ://治疗
    					rid = 190;
    					break;
    			}
    				var myAjax = $.ajax({
    					url : printUrl + "/printtemprest/findListByRid/" + rid+"?jsessionids="+$.cookie('jsessionids'),
    					type : "get",
    					async : true,
    					dataType : "json",
    					traditional : true,
    					success : function(data) {
    						$(".print_btn").removeAttr("disabled");
    						var html ="";
    						for (var i = 0; i < data.length; i++) {
    							var obj = {};
    							obj.vaf10 = vaf10;
    							obj.id = data[i]['id'];
    							if (data[i]['xdefault'] == "1") {
    								html += '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
    							} else {
    								html += '<option data-info='+JSON.stringify(obj)+'>'+data[i]['name']+'</option>';
    							}
    						}
    						$("#advice_print").empty().append(html);
    						print_content();
    					},
    					error : function(XMLHttpRequest, textStatus, errorThrown) {
    						layer.msg('打印服务器连接失败！', {
    							time : 2000,
    							icon : 3,
    							skin: 'layui-layer-msg3'
    						});
    						$(".print_btn").removeAttr("disabled");
    					}
    				});
//    			}
    			
    		}
    }
    
//只接诊
function onlyJieZhen(){
	debugger;
	isonlyJieZhen = true;
	hujiao_houtai();
}
	//后台呼叫-同步方法
function hujiao_houtai()
{
	var rowidT = $("#patient_wait").jqGrid('getGridParam','selrow');
	var row = $("#patient_wait").jqGrid("getRowData", rowidT);
	debugger;
	var beginTime;
	var endTime;
	beginTime = getDay(-1)+" 23:45:00:";
	endTime = getDay(0)+" 23:59:59:";
	var jiezhenfw = valueArr.p_100_105002_100;
//	jiezhenfw = '01';
	var fenzhen=1;
	if(valueArr.p_9999_9999_102==1 || valueArr.p_9999_9999_102=="1")
	{
		fenzhen=0;
	}
	else
	{
		fenzhen=1;
	}
	vac01_ =  rowidT?row.vac01:'';
	/*if(!vac01_){
		layer.msg("请选择要接诊的候诊病人！", {
			time : 4000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
		return false;
	}*/
	//弹出诊金选择框
	if(valueArr['p_100_105002_406']=='1')
	{
		//弹出诊金选择框-lbb
		
		
		hujiaoZhenjin(vac01_);
//		vbu09 = newCardOut(5);//弹出消费窗口
	}
	else
	{
		hujiao_(vac01_);
	}
	
}
function hujiaoZhenjin(pinfo){
	debugger;
	$.ajax({
		url:rootUrl+"/clidoctor/queryHasZj",
		type:"get",
		dataType:"json",
		async:false,
		data:{vac01:$("#vac01").val(),hours:valueArr['p_9999_9999_95']},
		success:function(data)
		{
			var flag = data.map.flag;
			if(flag)
			{
			$.ajax({
				url:rootUrl+"/clidoctor/queryAah1Bby1ByBce01",
				type:"get",
				async:false,
				dataType:"json",
				data:{params:JSON.stringify({bce01:bce01})},
				success:function(json){
				  laytplUrl(myurl + "/module/zhenjin.html",{}, function(data, html) {
					var index_z = layer.open({
						type : 1,
						// scrollbar : false,
						title : "选择诊查费",
						area : [ "500px", "500px"],
						shade : 0.1,
						maxmin : true,
						content : html,
						closeBtn : 1,
						cancel:function(){
						},
						success : function() {
							$("#zhenjin_table").empty();
							$("#zhenjin_table").GridUnload();
							jQuery("#zhenjin_table").jqGrid(
									{
										data : json.list,
										datatype : "local",
										height : 'auto',
										width : 'auto',
										autowidth : true,
										autoheight : true,
										multiselect : true,
//										multiboxonly:true,
										colModel : [
										            {
										            	label:'项目名称',
										            	name : 'bby05',
										            	align : 'left',
										            	width:'400'
										            },
										            {
										            	label : '单价',
										            	name : 'bby25',
										            	align : "left"
										            },
										            {
										            	name : 'bdn01',
										            	hidden : true
										            },
										            {
										            	name : 'bby01',
										            	hidden : true
										            },
										            ],
													beforeEditCell : function(rowid, cellname, value, iRow, iCol)
													{
													},
										            ondblClickRow : function(rowid, status)
										            {
										            }
									});
							$("#zhenjin_cancle").on("click",function(){
								layer.close(index_z);
							});
							//确定按钮
							$("#add_zhenji").on("click",function(){
								confirmHujiaoZhenjin(pinfo);
								layer.close(index_z);
							});
						}
					})

				});
			}});
			}
			else
			{
			}
		}
	});
}
//确定呼叫诊金
function confirmHujiaoZhenjin(pinfo){
	var selectedId = $("#zhenjin_table").jqGrid('getGridParam', 'selarrrow');
	if (selectedId && selectedId.length)
	{
		var vaa01_z = pinfo.vaa01;
		var vac01_z = pinfo.vac01;
//		var bce02_z =  $.cookie("loginName");
		var bce02_z =  loginName;
		for (var i = 0; i < selectedId.length; i++)
		{
			var row = $("#zhenjin_table").jqGrid("getRowData", selectedId[i]);
			var obj={};
			obj.vaa01 = vaa01_z;
			obj.vac01 = vac01_z;
			obj.bck01 = bck01;
			obj.bby25 = row.bby25;
			totalVbi+=parseFloat(row.bby25);
			obj.bce01 = bce01;
			obj.bce03 = bce03;
			obj.bce02 = bce02_z;
			zhenjinList.push(obj);
		}
		console.log(zhenjinList);
		vbu09 = newCardOut(5);//弹出消费窗口
	}
}
function hujiao_(vac01_g)
{
	debugger;
	$.ajax({
		url:rootUrl+"/clidoctor/hujiao_houtai",
		type:"get",
		dataType:"json",
		data:{
			vac01 : vac01_g?vac01_g:vac01_,
			lPara : valueArr.p_100_105002_100,
			lVAC51 : 0,
			lBCK01 : bck01,
			lBCE01 : bce01,
			BAS02 : '0001',
			fenzhen : fenzhen,
			beginTime :beginTime,
			endTime :endTime,
			lSign : 0,
			lBCK01 : $("#departmentList").find("option:selected").attr("id"),
			lBCE01 : bce01,
//			lBCE02 : $.cookie("loginName"),
			lBCE02 : loginName,
			lBCE03 : bce03,
			zhenjinVajList:JSON.stringify(zhenjinVajList)
		},
		success:function(data)
		{
			if(data)
			{
				var hujiaoRow = {};
				debugger;
				if(data.result=="Success")
				{
					hujiaoRow = data.map;
					//更新全局变量bck01为病人的挂号科室
					bck01 = hujiaoRow.bck01a;
					houzhenTbleList_houtai = data.list;
					//调用声音服务和外显服务
					huJiao1(hujiaoRow);
					if (hujiaoRow.bdp02!='自费')
					{
						//针对医保病人--调用智慧医保的remind接口
						remind(hujiaoRow);
					}
					refreshListJiezhen_jiezhen();
				}
				else
				{
					if(data.result=="Failure" && data.resultMsg=="no-body")
					{
						layer.msg("暂时没有候诊的病人！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
					}
					else if(data.result=="Failure" && data.resultMsg=="bad-tizhong")
					{
						//提示输入体重
						hujiaoRow = data.map;
						huJiao1(hujiaoRow);
						var data = {msg:"儿童需要录入体重"}
						laytplUrl_T(myurl + "/module/tizhong.html",data, function(data, html) {
							blood_index = layer.open({
								type : 1,
								title :"提示",
								area : [ "400px", "250px" ],
								shade : 0.1,
								content : html,
								closeBtn : 0,
								success : function() {
									$("#tizhong").focus();
									$("#saveTizhong").off("click").on("click",function(){
										layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
										debugger;
										var tizhong = $("#tizhong").val();
										if(tizhong && checkNumber(tizhong)){
											hujiaoRow.tizhong = tizhong;
											saveMoreInfo(hujiaoRow);
										}else{
											layer.msg("请输入正确的体重！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
										}
									})
								}
							})
						})
					}
					else if(data.result=="Failure" && data.resultMsg=="bad-blood")
					{
						//提示输入血压
						hujiaoRow = data.map;
						huJiao1(hujiaoRow);
						var data = {msg:data.total+"岁以上病人需要录入血压值"}
						laytplUrl_T(myurl + "/module/blood_pressure.html",data, function(data, html) {
							blood_index = layer.open({
								type : 1,
								title :"提示",
								area : [ "400px", "250px" ],
								shade : 0.1,
								content : html,
								closeBtn : 0,
								success : function() {
									$("#blood_pressure").focus();
									$("#save_blood_pressure").off("click").on("click",function(){
										layer.msg('加载中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
										debugger;
										var blood = $("#blood_pressure").val();
										if(blood && checkNumber(blood.split("/")[0])&&checkNumber(blood.split("/")[1])){
											hujiaoRow.blood = blood;
											saveMoreInfo(hujiaoRow);
										}else{
											layer.msg("请输入正确的血压！",{time:3000,icon:0,skin: 'layui-layer-msg0'});
										}
									})
								}
							})
						})
					}
					else
					{    
						//后台异常
						console.log(data.resultMsg);
					}
				}
			}
			totalVbi = 0;
			reflushPatientWait();
		},
		error:function(a,b,c){
			console.log(c);
		}
	});
}
	
function zaicihujiao()
{
	$.ajax({
		url:rootUrl + "/clidoctor/querybas02Bybce01",
		type:'get',
		data:{bce01:bce01},
		datatype:"json",
		async:false,
		success:function(data)
		{
			var hJId = $("#myjiezhenTableList").jqGrid("getGridParam",'selrow');
			var hJrow = $("#myjiezhenTableList").jqGrid('getRowData',hJId);
			hJrow.bas02a = localStorage.bas02;
			hJrow.bce03a = bce03;
			if (!hJId) 
			{
				layer.msg("请选择要呼叫的候诊病人", {
					time : 2000,
					icon : 0,
					skin: 'layui-layer-msg0'
				});
			} 
			else 
			{
				debugger;
				//发送当前叫号病人到消息中心
				$.ajax({
//					url : hosturl + "/bck1Config.json",
					url : rootUrl + "/clidoctor/queryZhentaiConfig",
//					url : "http://192.168.129.131:8089/tts/speak",
					type : "get",
					data:{bck01:bck01},
					dataType : "json",
					success : function(data)
					{
						var type = data.list[0].triage_id;
						//呼叫病人
						var msg = "请"+(hJrow.vad21?(hJrow.vad21+"号"):'')+hJrow.vaa05+"到"+hJrow.bck03+(hJrow.bas02a?hJrow.bas02a:"")+"就诊";
						$.ajax({
							url:data.list[0].ttsurl,
//							url:"http://192.168.1.161:8765/tts/speak",
							type:"get",
							dataType:"json",
							data:{text:msg,comid:2,comstr:msg},
							success:function(data)
							{
								console.log(data);
							},
							error : function(a,b,c)
							{
								console.log(c);
							}
						});
						var message = {};
						message.hJrow = hJrow;
//						message.houzhenList = houzhenTbleList_houtai;
						//同步外显
						$.ajax({
							url:mqUrl+"/Mq/MMC/sendCallsystem",
							type:"get",
							dataType:"jsonp",
							data:{message:JSON.stringify(message),topic:type,jsessionids:jsessionids},
							timeout : 1000, //超时
							success:function(data)
							{
								console.log(data);
							}
							});
					},
					error : function(a,b,c)
					{
						console.log(c);
					}
				});
				
			}
		}
	});
}	
	//呼叫病人
function huJiao1(hJrow)
{
			debugger;
			console.log(isonlyJieZhen);
			if(isonlyJieZhen){
				return false;
			}
    		var mode = paiban();
			if (mode!=1)
			{
				hJrow.bas02a = localStorage.bas02;
			}
			hJrow.bce03a = bce03;
			if (!hJrow) 
			{
				layer.msg("请选择要呼叫的候诊病人", {
					time : 2000,
					icon : 0,
					skin: 'layui-layer-msg0'
				});
			} 
			else 
			{
				debugger;
				//发送当前叫号病人到消息中心
				$.ajax({
//					url : hosturl + "/bck1Config.json",
					url : rootUrl + "/clidoctor/queryZhentaiConfig",
					// url : "http://192.168.129.131:8089/tts/speak",
					type : "get",
					data:{bck01:bck01},
					dataType : "json",
					success : function(data)
					{
						console.log('------------------------------------呼叫');
						var type = data.list[0].triage_id;
						var hJrow2;
						if(houzhenTbleList_houtai[1])
						{
							hJrow2 = houzhenTbleList_houtai[1];
						}
						debugger;
						var msg = "请"+(hJrow.vad21?(hJrow.vad21+"号"):'')+hJrow.vaa05+"到"+hJrow.bck03+(hJrow.bas02a?hJrow.bas02a:"")+"就诊";
						if(hJrow2)
						{
							msg += "请"+(hJrow2.vad21?(hJrow2.vad21+"号"):'')+hJrow2.vaa05+"做准备";
						}
						$.ajax({
							url:data.list[0].ttsurl,
//							url:"http://192.168.129.131:8089/tts/speak",
							type:"get",
							dataType:"json",
							data:{text:msg,comid:2,comstr:msg},
							success:function(data)
							{
								console.log(data);
							},
							error:function(a,b,c)
							{
								console.log(a);
								console.log(b);
								console.log(c);
							}
						});
						var message = {};
						message.hJrow = hJrow;
//						message.hJrow2 = hJrow2;
						//message.houzhenList = houzhenTbleList_houtai;
						console.log("分诊台topic:"+type);
						//同步外显
						debugger;
						$.ajax({
							url:mqUrl+"/Mq/MMC/sendCallsystem",
							type:"get",
							dataType:"jsonp",
							data:{message:JSON.stringify(message),topic:type,jsessionids:jsessionids},
							timeout : 1000, //超时
							success:function(data)
							{
								console.log(data);
							},
							error:function(a,b,c)
							{
								console.log(a);
								console.log(b);
								console.log(c);
							}
							});
					},
					error : function(a,b,c)
					{
						console(c);
					}
				});
				isonlyJieZhen = false;
			}
		/*}
	});*/
	
}

/**
 * 保存体重、血压
 */
function saveMoreInfo1(type)
{
	debugger;
	var tz = $("#tz").val();
	var xueya = $("#xueya").val();
	var ssy; //04 大
	var szy; //05 小
	if (xueya)
	{
		ssy = xueya.split("/")[0];
		szy = xueya.split("/")[1];
	}
//	if(checkNumber(szy)&&checkNumber(ssy)||$("#tz").val()){
	var params = {};
	params.vaa07 = $("#vac01").val();
	params.vaa01 = $("#vaa01").val();
	if(tz){
		params.vac63 = tz;
	}
	if(checkNumber(szy)&&checkNumber(ssy))
	{
		params.vcj04 = parseInt(ssy) > parseInt(szy) ? ssy : szy;
		params.vcj05 = parseInt(ssy) < parseInt(szy) ? ssy : szy;
	}else{
		layer.msg("请输入正确的血压！", {time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'});
			
		return;
	}
	$.ajax({
		url:rootUrl+"/clidoctor/savePatientMore",
		type:"post",
		dataType:"json",
		data:params,
		success:function(data)
		{
			if(data && data.result=="Success")
			{
				if(type){
				layer.msg("保存成功！", {time : 2000,
					icon : 1,
					skin: 'layui-layer-msg1'});
					
				}
			}
			else
			{
				layer.msg("保存失败！", {time : 2000,
					icon : 2,
					skin: 'layui-layer-msg2'});
			}
		},
		error:function(a,b,c)
		{
			console.log(c);
		}
	});
//	}
}

/**
 *取消接诊 
 */
function quxiaojiezhen()
{
	var rowid = $("#myjiezhenTableList").jqGrid('getGridParam','selrow');
	var row = $("#myjiezhenTableList").jqGrid("getRowData", rowid);
	debugger;
	var flag1;
	if (rowid) {
		$.ajax({url:rootUrl+"/doctoradvice/checkpatientdoctoradvice",
			data:{vaa01:$("#vaa01").val(),vaf06:row.vac01},
			async:false,
			type:'post',
			dataType:"json",
			success:function(data){
			if(data && data.list && data.list.length>0)
			{
				flag1 = true;
			}
		}
		})
		if(flag1)
		{
			layer.msg("该病人有医嘱，不能取消接诊！", {
				time : 2000,
				icon : 2,
				skin: 'layui-layer-msg2'
			});
			return;
		}
		// 获取选中行的值
//		var vac01 = $("#vac01").val();
//		var vaa01 = $("#vaa01").val();
		$.ajax({
			url : rootUrl + "/clinicalreceptiontransfer/clinicvac1update",
			data : {
				lVAA07 : row.vac01,
				lVAA01 : row.vaa01,
				lSign : 1,
				lBCK01 : bck01,
				lBCE01 : bce01,
				lBCE02 : '',
				lBCE03 : bce03
			},
			type : "post",
			dataType : 'json',
			success : function(data) {
				asyncHouzhenTable();
				asyncMyPatientTable();
//				benkeJiezhenPatientList();
			}
		});
	} else {
		layer.msg("请选择要接诊的病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}
}
function closeAndPrint(sobj)
{
	debugger;
	var lvac01 = sobj.vac01,flag = sobj.flag,list = sobj.list,msg = sobj.msg
	layer.closeAll();
	printIm(flag,list);
	reloadPatientInfo(lvac01);
	var vipId = $("#vipId").text();
	if (valueArr['p_100_105002_362']=='1' && vipId != "--" &&msg)
	{
		var indexl = layer.alert(msg,
		{
		icon : 1,
		title : "温馨提示：",
		yes:function(){
			isInfectionsDisease(sobj.sql); //传染病报告卡
			layer.close(indexl);
		},
		cancel:function(){
			isInfectionsDisease(sobj.sql); //传染病报告卡
			layer.close(indexl);
		}
		});
	}else{
		isInfectionsDisease(sobj.sql); //传染病报告卡
	}
	
}
function checkNumber(theObj) 
{
	debugger;
	  var reg = /^[1-9]\d*|0$/;
	  if (reg.test(theObj)) 
	  {
	    return true;
	  }
	  return false;
}
function testSend()
{
	// 开始异步发送
	$.ajax(
	{
	async : true,
	url : rootUrl + "/clisendadvice/clinicadvicesend",
	data :
	{
		"savePrintList":'[]',
		"lXml" : '{"VAF1":"[{vaf01:887157594316083202}]","VBD1":[{"vaf01":"887157594316083202","bby01":3350,"vbd04":1,"bby25":21.9,"vbd05":21.9,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3356,"vbd04":1,"bby25":7.6,"vbd05":7.6,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3337,"vbd04":1,"bby25":7.6,"vbd05":7.6,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3339,"vbd04":1,"bby25":7.6,"vbd05":7.6,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3333,"vbd04":1,"bby25":7.6,"vbd05":7.6,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3335,"vbd04":1,"bby25":7.6,"vbd05":7.6,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3936,"vbd04":1,"bby25":66.5,"vbd05":66.5,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3272,"vbd04":1,"bby25":33.3,"vbd05":33.3,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":3799,"vbd04":1,"bby25":38,"vbd05":38,"vbd06":1,"bck01":68,"bdn01":"L","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1},{"vaf01":"887157594316083202","bby01":2970,"vbd04":1,"bby25":5.7,"vbd05":5.7,"vbd06":1,"bck01":68,"bdn01":"T","vbd08":1,"vbd09":0,"bby01a":11576,"vbd12":1}],"zjAddList":[]}',
		"lSign" : 2,
		"lBCE01" : '1',
		"lBCE02" : "",
		"lBCE03" : '管理员',
		"lBCK01" : '32',
		"lACF01" : 1,
		"lVAA07" : '886870894889144321',
		"lVAA01" : '886870894889144320',
	},
	dataType : "json",
	method : "post",
	success : function(data)
	{
		if (data.result == "Success")
		{
			savePrintList = data.list;
			layer.msg('发送成功',
			{
			time : 3000,
			icon : 1,
			skin : 'layui-layer-msg1'
			});
			// 开始更新医嘱抄送记录和生成诊疗申请单
			var url9 = rootUrl + "/clidoctor/nurse_Lis_Bills_Print_batch";
			var params9 = {};
			params9.bce03 = '管理员';
			params9.cbm01Arr = '[{"cbm01":"887157594316083200","bda01":"L"}]';
			$.ajax(
			{
			async : false,
			url : url9,
			type : 'post',
			dataType : 'json',
			data : params9,
			success : function(data9)
			{
			}
			});

		}
	}
	});
}


/**
 * 点击确认诊金交易的事件
 */
function zhenjin_chareCardUpdate()
{
	$.ajax({
		url: rootUrl + "/clidoctor/getMD5PassWord",
		type: "GET",
		dataType: 'json',
		data: {password:$("#vbu09").val()},
		success:function(json){
			debugger;
		if(cardMap.vbu09 != json.pass)
		{
			layer.alert("密码错误，请重新输入");
		}
		else if(cardMap.vbu09 == json.pass)
		{
			debugger;
			layer.closeAll();
			//
			var postData = {};
			postData.grid2rows = grid2rows;
			postData.mydata = mydata;
			postData.zhenjinList = JSON.stringify(zhenjinList);
			hujiao_(vac01_);
		}
	}});
}

